package com.wedo.mall.adapter;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.e.library.adapter.Adapter;
import com.e.library.adapter.EAdapter;
import com.wedo.mall.R;
import com.wedo.mall.activity.user.ExchangeActivity;
import com.wedo.mall.entity.PointLog;
import com.wedo.mall.util.DateUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Lawrence on 2017/8/4.
 */

public class IntegralDetailAdapter extends Adapter<PointLog> {

    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    public IntegralDetailAdapter(Context context, List<PointLog> pointLogs) {
        super(context, pointLogs);
    }

    @Override
    protected int layout() {
        return R.layout.item_pointlog;
    }

    @Override
    protected void bind(EHolder holder, final PointLog pointLog, int position) {
        TextView tv_event= holder.find(R.id.tv_event);
        TextView tv_time= holder.find(R.id.tv_time);
        TextView label_exchange_details = holder.find(R.id.label_exchange_details);
        RelativeLayout rl_pointlog = holder.find(R.id.rl_pointlog);

        tv_event.setText(pointLog.event);
//        tv_time.setText(format.format(new Date(Integer.parseInt(pointLog.add_time))));
        tv_time.setText(DateUtils.convert(format,pointLog.add_time));
        if(pointLog.type.equals("0")){
            label_exchange_details.setVisibility(View.VISIBLE);
            rl_pointlog.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ExchangeActivity.toExchangeDetail(mContext,pointLog.order_sn,"1");
                }
            });
        }else{
            label_exchange_details.setVisibility(View.GONE);
            rl_pointlog.setOnClickListener(null);
        }
    }
}
